/*
 * Created by JFormDesigner on Sat Aug 16 17:26:32 CST 2025
 */

package org.xl.main.unicode;

import cn.hutool.core.text.UnicodeUtil;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Windows
 */
public class UniCodeFrame extends JFrame {
    public UniCodeFrame() {
        initComponents();
    }

    private void bmBtnOk(ActionEvent e) {
        // TODO add your code here
        String text = textArea1.getText();
        String unicode = UnicodeUtil.toUnicode(text);
        textArea2.setText(unicode);
    }

    private void jmBtnOk(ActionEvent e) {
        // TODO add your code here
        String text = textArea1.getText();
        String unicode = UnicodeUtil.toString(text);
        textArea2.setText(unicode);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        scrollPane1 = new JScrollPane();
        textArea1 = new JTextArea();
        textArea2 = new JTextArea();
        button1 = new JButton();
        button2 = new JButton();
        label2 = new JLabel();

        //======== this ========
        setTitle("Unicode\u7f16\u89e3\u7801");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u539f\u5b57\u7b26\u4e32:");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(25, 10), label1.getPreferredSize()));

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(textArea1);
        }
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(30, 35, 1600, 155);
        contentPane.add(textArea2);
        textArea2.setBounds(35, 220, 1600, 600);

        //---- button1 ----
        button1.setText("\u7f16\u7801");
        button1.addActionListener(e -> bmBtnOk(e));
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(160, 190), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u89e3\u7801");
        button2.addActionListener(e -> jmBtnOk(e));
        contentPane.add(button2);
        button2.setBounds(320, 190, 74, 25);

        //---- label2 ----
        label2.setText("\u7ed3\u679c\u96c6:");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(30, 200), label2.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JScrollPane scrollPane1;
    private JTextArea textArea1;
    private JTextArea textArea2;
    private JButton button1;
    private JButton button2;
    private JLabel label2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
